/* add to fav */
function addfav(url,title){var fav_url = url;var fav_title = title;if (document.all && window.external){window.external.AddFavorite(fav_url,fav_title);}else if (window.sidebar){window.sidebar.addPanel(fav_title,fav_url,"");}else{alert(js_fav);} }

// change language 改变语言
function set_lang(lang,currency){
	$.cookie('lang', lang, '{ expires: 14,secure: true}'); top.location.reload();
	set_currency(currency);
}
function set_currency(currency){
	$.cookie('currency', currency, '{ expires: 14,secure: true}'); top.location.reload();
}
/* confirm delete */
function delc(){ return confirm(js_comfirm_delete);}
function operator(){ return confirm(js_comfirm_operator);}
function checkf(id){
	if($(id).val()=='') return false; return true;
}
function add_to_cart(){
	$.get("ajax_cart.php",{'pid':$('#buy-pid').val(),'varid':$('#buy-var').val(),'qty':$('#buy-qty').val(),'do':'add'}, function(data){
		//alert(data);
		$('.toolcart').parent().remove();$('.center_box').fadeIn();$('#cart_qty').html(data);
    });
}
function add_to_cart_multi(i,refresh){
	$.get("ajax_cart.php",{'pid':$('#buy-pid'+i).val(),'varid':$('#buy-var'+i).val(),'qty':$('#buy-qty'+i).val(),'do':'add'}, function(data){
		//alert(data);
		$('.toolcart').parent().remove();
		$('#cart_qty').html(data);
		$.get("ajax_cart.php",{'do':'get_order_price'}, function(data){
			//alert(data);
			$('#cart_order_price').html(data);
			if(refresh) {
				location.reload();
			}
		});
    });
}
function cart_qty_add(pid,varid,qty,max){
	if(qty==max) { $.notice(js_max_stock); return false; }
	else qty=qty+1;
	$.get("ajax_cart.php",{'pid':pid,'varid':varid,'qty':qty,'do':'update'}, function(data){
		top.location.reload();
    });
	}
function cart_qty_reduce(pid,varid,qty){
	if(qty==1) return false;
	else qty=qty-1;
	$.get("ajax_cart.php",{'pid':pid,'varid':varid,'qty':qty,'do':'update'}, function(data){
		top.location.reload();
    });
}
function cart_qty_update(pid,varid,qty,max){
	if(qty>max) qty=max;
	$.get("ajax_cart.php",{'pid':pid,'varid':varid,'qty':qty,'do':'update'}, function(data){
		top.location.reload();
    });
}
function cart_remove(pid,varid){
	$.get("ajax_cart.php",{'pid':pid,'varid':varid,'do':'remove'}, function(data){
		top.location.reload();
    });
}
function cart_clear(){
	$.get("ajax_cart.php",{'do':'clear'}, function(data){
		top.location.reload();
    });
}
function history_clear(){
	$.get("ajax_history.php",{'do':'clear'}, function(data){
		$('.history').fadeOut(); $.notice(js_history_cleared);
    });
}
function order_submit(){
	$('.order_form').submit();
}
function ajax_delete(table,id){
	if(!confirm(js_comfirm_delete)) return false;
	var div = '.delete'+id;$.get("ajax_delete.php","table="+table+"&id="+id, function(msg){
		if(msg=='1'){
		$(div).fadeOut('slow').remove(); $.notice(js_deleted);
	}});
}
function qty_add (qty,maxer){
		var div='#'+qty;
		$(div).val( parseInt($(div).val()) +1);if(parseInt($(div).val())>maxer)$(div).val(maxer);
	}
function qty_reduce(qty){
		var div='#'+qty;
		$(div).val( parseInt($(div).val()) - 1);if(parseInt($(div).val())<1)$(div).val(1);
	}
function payoff(id){
		var div='.shipfee'+id; var payoff=0;
		$('.shipfee').html($(div).val());
		$('.shipfeeinput').val($(div).val());
		payoff=(parseFloat($(div).val())+parseFloat($('#subtotal').html())).toFixed(2);
		$('#payoff').html(payoff);
		$('#L_AMT0').val(payoff);
}
function goto(url){ window.location = url; }
function tabs(tabPreName,pagePrefix,totalPageNum,currentPageNo){
	for( var i = 0; i < totalPageNum; i++){
		document.getElementById(tabPreName+i).className ='b';//按钮背景
		document.getElementById(pagePrefix+i).style.display="none";//切换的页面
	}
	document.getElementById(tabPreName+currentPageNo).className ='h';//按钮背景
	document.getElementById(pagePrefix+currentPageNo).style.display="block";//切换的页面
}
function search(){
	if(! checkf('.search-text')) { $('.search-text').focus(); return false; }
	return true;
}

// jQuery 扩展
$.extend({
 notice:function (options){
 	//var params=options?options:{'message':'This is a notice','timer':2};
 	var str='<div class="notice"><div>'+options+'</div></div>';
 	$('body').append(str);
 	$('.notice').css('top',($(window).height())/2-($('.notice').height()));
	$('.notice').css('left',($(window).width())/2-($('.notice').width()/2));
 	var timer = 3.8*1000;
	setTimeout("$('.notice').fadeIn()", 380);
	setTimeout("$('.notice').fadeOut('slow').remove()", timer);
	//$('.notice');
 }});
$.extend({
 warning:function (options){
 	var close=js_close;
 	var str='<div class="mask_overlay"><div class="mask_box"><div class="mask_boxer"><div class="mask_message">'+options+'</div><div class="mask_close"><a onclick="$(\'.mask_overlay\').fadeOut().remove();">[ '+close+' ]</a></div></div></div></div>';
 	$('body').append(str);
	$('.mask_overlay').css('height',$('body').height()+200);
	$('.mask_box').css('left',($(window).width())/2-($('.mask_box').width()/2));
	$('.mask_box').css('top',($(window).height())/2-($('.mask_box').height()));
	setTimeout("$('.mask_overlay').fadeIn()", 38);
 }
});
// document ready
$(document).ready(function(){
	$(".simg img").hover(function(){ 
		$(this).parent().parent().parent().find('img').removeClass('h'); $(this).addClass('h');
		$('#gimg img').attr('src',$(this).attr('pic'));$('#gimg img').attr('jqimg',$(this).attr('pic'));
 })
	// 评分效果
    $("ul.rating li a").click(function(){
	     var title = $(this).attr("title");
	     //alert("您给此商品的评分是："+title);
		 var cl = $(this).parent().attr("class");
		 $(this).parent().parent().removeClass().addClass("rating "+cl+"star");
		 $('.rating').val($(this).html());
		 $(this).blur();//去掉超链接的虚线框
		 return false;
	})
	// 新闻/公告切换
	$('.tab_news li').hover(function(){
		$(this).siblings().removeClass('h');
		$('.'+$(this).siblings().attr('link')).addClass('hide');
		$(this).addClass('h');
		$('.'+$(this).attr('link')).removeClass('hide');
	})
	// 弹出 message
	if($.cookie('message')) { var s=$.cookie('message');s=s.replace(/\+/g,' ');$.notice(s);$.cookie('message',null); }
	// 弹出 warning
	if($.cookie('warning')) { var s=$.cookie('warning');s=s.replace(/\+/g,' ');$.warning(s);$.cookie('warning',null); };
 });
